<?php
    foreach ($getDetail as $row) {
        $rOrderID 		= $row['ORDER_ID'];
    	$rOrderDesc 	= $row['ORDER_DESCRIPTION'];
    	$rOrderFor 		= $row['ORDER_FOR'];
    	$rHrID 			= $row['HR_ID'];
    	$rOrderStatus 	= $row['ORDER_STATUS'];
    	$rOrderAwal 	= $row['ORDER_TGL_AWAL'];
    	$rOrderAkhir 	= $row['ORDER_TGL_AKHIR'];
    	$rOrderDate 	= $row['ORDER_DATE'];
    	$rId 			= $row['ID'];
    	$rName 			= $row['NAME'];
    	$rOrg 			= $row['ORG'];
    	$rJob 			= $row['JOB_POSITION'];
    	$rHrName  		= $row["NAMEBYHRID"];
    	$rHrOrg  		= $row["ORGBYHRID"];
    	$rHrJob  		= $row["JOBBYHRID"];
    }
    
    
?>

<script>
    function cancel() {
        $.post("<?= site_url() ?>search_global", function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        });
    }
    function appGaServicesSave() {
        $pJumlahInventory=$('#pJumlahInventory').val();
        
    	if ($('#pApproval').val()=='N'&&$('#pComment').val().length==0) {
    		alert('Comment harap diisi');
            document.getElementById('pComment').focus();
    		return false; //menghasilkan nilai false, artinya jika script di bawahnya tidak akan dijalankan, berguna banget untuk POP UP
    	}
        
        var arrCheck=[""];
        var arrItemId=[""];
        var x=0;
        for($x=0;$x<$pJumlahInventory;$x++){
            arrCheck[$x]=document.getElementById('cek'+$x).value;
            arrItemId[$x]=document.getElementById('pWareItemId'+$x).value;
        }
        
        //alert(arrCheck);
        
        $.post("<?= site_url() ?>search_global/approve_gaServicesSave", {
            pOrderID: $('#pOrderID').val(),
            pApproval: $('#pApproval').val(),
            pComment: $('#pComment').val(),
            pNikRequestBy: $('#pNikRequestBy').val(),
            //pCheck: [pJumlahInventory, 100, 1, 5, 25, pJumlahInventory]
            pCheck: arrCheck,
            pWareItemId: arrItemId
        },
        function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        }
        );
        
    }
</script>


<form id="formarea" role="form" method="post" action="#">
    <input type="hidden" value="<?php echo $cRequestNo; ?>" id="pOrderID" />
    <input type="hidden" id="pParkirdId" value="<? echo $pParkirdId;?>" />
    <input type="hidden" value="<?php echo $cTab; ?>" id="pCTab" />
    <input type="hidden" value="<?php echo $cType; ?>" id="pCType" />
    <input type="hidden" value="<?php echo $rId;?>" id="pNikRequestBy" name="pNikRequestBy"/>            
<div class="col-md-offset-0" id="top">
    <div class="col-md-11">
        <div class="panel panel-default">
			<div class="panel-heading">
            <h4 class="panel-title"><b> Request By </b></h4>
            </div>
            <div class="panel-body">
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-2">NIK</label>
    						<div class="col-md-4">
                                <input class="form-control input-form" id="pNip" style="width:100%" value="<?php echo $rHrID; ?>" readonly=""/>
    						</div>
                            <label class="control-label col-md-2">Nama</label>
    						<div class="col-md-4">
                                <input class="form-control input-form" id="pRequestor" style="width:100%" value="<?php echo $rHrName; ?>" readonly=""/>
    						</div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-2">Departement</label>
    						<div class="col-md-4">
                                <input class="form-control input-form" id="pDepartemen" style="width:100%" value="<?php echo $rHrOrg; ?>" readonly=""/>
    						</div>
                            <label class="control-label col-md-2">Job Position</label>
    						<div class="col-md-4">
                                <input class="form-control input-form" id="pPosition" style="width:100%" value="<?php echo $rHrJob; ?>" readonly=""/>
    						</div>
				        </div>
                    </div>                   
                </div>
            </div>
        </div>
          
         
        <div class="panel panel-default">
			<div class="panel-heading">
			<h4 class="panel-title"><b> Requestor </b></h4>
			</div>
			<div class="panel-body">
            
                
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">NIK</label>
    						<div class="col-md-9">
                            <?
                    			echo $rId;
                    		?>
                            </div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Nama</label>
    						<div class="col-md-9"><?php echo $rName; ?></div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Department</label>
    						<div class="col-md-9"><?php echo $rOrg; ?></div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Job Position</label>
    						<div class="col-md-9"><?php echo $rJob ; ?></div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Tanggal</label>
    						<div class="col-md-9"><?php echo $rOrderAwal." - ".$rOrderAkhir; ?></div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Penggunaan Untuk</label>
    						<div class="col-md-9"><?php echo $rOrderDesc; ?></div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Comment</label>
    						<div class="col-md-4">
                                <textarea class="form-control input-sm" id="pComment"></textarea>
    						</div>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">Approval</label>
    						<div class="col-md-4">
                                <select class="form-control input-form select2" id="pApproval" style="width:100%">
                        			<option value="Y">Approve</option>
                                    <option value="N" selected="">Disapprove</option>
				                </select>
    						</div>
				        </div>
                    </div>                   
                </div>
                
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
				        </div>
                    </div>                   
                </div>
                <div class="table-responsive">
                                <table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
                                    <thead>
                                        <tr>
                                            <th class="tblhead" style="width:15%;text-align:center;">Approve</th>
                                            <th class="tblhead" style="width:5%;text-align:center;">No</th>
                                            <th class="tblhead" style="width:5%;text-align:center;">Ware Item ID</th>
                                            <th class="tblhead" style="width:55%;text-align:center;">Item Name</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Total Qty Reservation</th>
                                            <th class="tblhead" style="width:10%;text-align:center;">Total Available</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $i=0;
                                        foreach ($getDetail2 as $row2) {
                                            $aWareItemName  = $row2["WAREHOUSE_NAME"];
    										$aWareItemQty 	= $row2['ORDER_DET_QTY'];
    										$aWareItemAvail	= $row2['WAREHOUSE_ITEM_QTY_IN'];
    										//$aWareItemId	= $row2['ORDER_DET_ID'];
                                            //saya ubah dengan mempertimbangkan 
                                            //where det.WAREHOUSE_ID = '$pWareItemId[$i]' pada order_app_ga_act, -> sGlobal_model/
                                            $aWareItemId	= $row2['WAREHOUSE_ID'];
    										$oddeven = $oddeven=="even"?"odd":"even";
                                            ?>
                                        <input type="hidden" id="pWareItemId<?php echo $i; ?>"   value="<?php echo $aWareItemId; ?>" />
                                        
                                        <tr>
                                            <td style="font-size:10px;">
                                            <select class="form-control input-form select2" id="cek<?php echo $i; ?>" style="width:100%" name="cek[<?php echo $i; ?>]">
                                    			<?php
                                                if($aWareItemQty<=$aWareItemAvail){ //jika order kurang dari stock
                                                ?>
                                                <option value="Y">Approve</option>
                                                <?php
                                                }
                                                ?>
                                                <option value="N" selected="">Disapprove</option>
            				                </select>
                                            </td>
                                            <td style="font-size:10px;"><?php echo ++$i; ?></td>
                                            <td style="font-size:10px;"><?php echo $aWareItemId; ?></td>
                                            <td style="font-size:10px;"><?php echo nl2br($aWareItemName);?></td>
                                            <td style="font-size:10px;"><?php echo $aWareItemQty; ?></td>
                                            <td style="font-size:10px;"><?php echo $aWareItemAvail; ?></td>
                                        </tr>
                                        <?php
                                        }
                                        ?>
                                        <input type="hidden" id="pJumlahInventory"   value="<?php echo $i; ?>" />
                                    </tbody>
                                </table>
                            </div>
                
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3"></label>
				        </div>
                    </div>                   
                </div>
                <div class="row"> 
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label col-md-3"></label>
    						<div class="col-sm-2">
                                <button type="button" class="btn btn-primary btn-block" onclick="appGaServicesSave();">Submit</button>
                            </div>
                            <div class="col-sm-2">
                                <button type="button" class="btn btn-default btn-block" onclick="cancel();" >Cancel</button>
                            </div>
				        </div>
                    </div>                   
                </div>
            </div>
        </div>
        
        
    </div>
</div>
</form>